-- function is the first-classvalue, which means fucntion can be assigned to a variable (or as a parameter)
-- all function in lua is anoymous

-- syntax is different, but they are the same thing
--[[ 
function foo (x)
	return x	
end
--]]

-- function as variable
foo = function (x) return x end

network = {
	{name = "grauna",  IP = "210.26.30.34"},
	{name = "arraial", IP = "210.26.30.23"},
	{name = "lua", 		 IP = "210.26.23.12"},
	{name = "derain",  IP = "210.26.23.20"},
}

-- function as parameter
table.sort(network, function (a, b) return (a.name > b.name) end) 	-- reverse order

-- function as field
Lib = {
	add = function (x, y) return x + y end,
	sub = function (x, y) return x - y end,
	mul = function (x, y) return x * y end,
	div = function (x, y) return x / y end,
}

function Lib.fact (n) 
	if n = 0 	then return 1 
	else return n * fact(n - 1) 
	end
end

-- local function 
local f = function (x) return x end
local function g (x) return x end
